//
//  FLData.m
//
//  Created by   on 2019/2/23
//  Copyright (c) 2019 __MyCompanyName__. All rights reserved.
//

#import "FLData.h"


NSString *const kFLDataMoney = @"money";
NSString *const kFLDataUid = @"uid";
NSString *const kFLDataType = @"type";
NSString *const kFLDataTypeId = @"type_id";
NSString *const kFLDataTime = @"time";


@interface FLData ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation FLData

@synthesize money = _money;
@synthesize uid = _uid;
@synthesize type = _type;
@synthesize typeId = _typeId;
@synthesize time = _time;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict {
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if (self && [dict isKindOfClass:[NSDictionary class]]) {
            self.money = [self objectOrNilForKey:kFLDataMoney fromDictionary:dict];
            self.uid = [self objectOrNilForKey:kFLDataUid fromDictionary:dict];
            self.type = [self objectOrNilForKey:kFLDataType fromDictionary:dict];
            self.typeId = [self objectOrNilForKey:kFLDataTypeId fromDictionary:dict];
            self.time = [self objectOrNilForKey:kFLDataTime fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation {
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.money forKey:kFLDataMoney];
    [mutableDict setValue:self.uid forKey:kFLDataUid];
    [mutableDict setValue:self.type forKey:kFLDataType];
    [mutableDict setValue:self.typeId forKey:kFLDataTypeId];
    [mutableDict setValue:self.time forKey:kFLDataTime];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description  {
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super init];

    self.money = [aDecoder decodeObjectForKey:kFLDataMoney];
    self.uid = [aDecoder decodeObjectForKey:kFLDataUid];
    self.type = [aDecoder decodeObjectForKey:kFLDataType];
    self.typeId = [aDecoder decodeObjectForKey:kFLDataTypeId];
    self.time = [aDecoder decodeObjectForKey:kFLDataTime];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_money forKey:kFLDataMoney];
    [aCoder encodeObject:_uid forKey:kFLDataUid];
    [aCoder encodeObject:_type forKey:kFLDataType];
    [aCoder encodeObject:_typeId forKey:kFLDataTypeId];
    [aCoder encodeObject:_time forKey:kFLDataTime];
}

- (id)copyWithZone:(NSZone *)zone {
    FLData *copy = [[FLData alloc] init];
    
    
    
    if (copy) {

        copy.money = [self.money copyWithZone:zone];
        copy.uid = [self.uid copyWithZone:zone];
        copy.type = [self.type copyWithZone:zone];
        copy.typeId = [self.typeId copyWithZone:zone];
        copy.time = [self.time copyWithZone:zone];
    }
    
    return copy;
}


@end
